<template>
	<view>
		<uni-nav-bar left-icon="back" left-text="返回" fixed="true" statusBar="true"  @clickLeft="leftAction"  :title="clientId+'报警数据'"
			></uni-nav-bar>
		<uni-list>
			<template v-for="(item,index) in dataArr">
				<uni-list-item  :note="item.time" :rightText="item.value" />
			</template>
		</uni-list>	
	</view>
</template>

<script>
	import uniNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'
	import Vue from 'vue'
	
	export default {
		data() {
			return {
				dataArr:[]
			};
		},
		onLoad(options) {
			this.clientId = options.clientId
			var time = this.$moment().format("yyyy-MM-DD HH:mm:ss")+'.000';
			var starttime = this.$moment().subtract(1, 'days').format("yyyy-MM-DD HH:mm:ss")+'.000';		
			const params = {
					"tags": [this.clientId + '_DV.PV'],
					"count":"100","unit":"-1","level":"-1","cat":"-1","org":"",
					"starttime":starttime,
					"endtime":time,
					"type":"GetHisAlarm",
					"token":Vue.prototype.token
				}
			this.$http.post('/realhistorian/requestJson',params).then(res => {
				const array = res.data.data.items.reverse()
				this.dataArr = []
				
				for (let i in array) {
					const item = array[i]
					this.dataArr.push({
						value:item['val'].toFixed(2),
						time:this.$moment(item['time']).format('yyyy-MM-DD HH:mm:ss')
					})
				}
				
			}).catch(err => {
				uni.showModal({
					content: '出错了，请稍后再试',
					showCancel: false
				})
			})
		},
		
		components: {
			uniNavBar
		},
		methods: {
			leftAction() {
				uni.navigateBack({
					delta: 1
				});
			},
		}
	}
</script>

<style lang="scss">
	@import '@/common/uni-nvue.scss';
</style>
